//
//  QQMiniAppSDKManager.h
//  QQMiniAppSDK
//
//  Created by linseyzhou on 2020/5/14.
//

#import <Foundation/Foundation.h>
#import "QQMAProtoObject.h"
#import "QMASDKDelegate.h"
#import "QMAEntrySceneDefine.h"
#import "QMAContextDelegate.h"
#import "QMAAppEnvironmentDelegate.h"
#import "QQDownloadDelegate.h"
#import "QMAConfigDelegate.h"
#import "QMACacheDelegate.h"
#import "QMAUIDelegate.h"
#import "QMAVoIPDelegate.h"
#import "QMAFeatureToggleDelegate.h"
#import "QMAShareDelegate.h"
#import "QMADelegateDefine.h"
#import "QQNetworkEngine.h"
#import "QMAErrorDefine.h"
#import "QMAStartErrorDefine.h"
#import "QMAStartUpProtocol.h"
#import "QMAWnsConfigDefine.h"
#import "QQNetworkChannelDelegate.h"
#import "QMAAdvDelegate.h"
#import "QMAHostModel.h"

NS_ASSUME_NONNULL_BEGIN

OBJC_EXPORT NSErrorDomain const QMASDKProtoCodecErrorDomain;

NS_ERROR_ENUM(QMASDKProtoCodecErrorDomain) {
    QMASDKProtoCodecErrorUnknown = -1,
    
    QMASDKProtoCodecErrorDecodeQWebRsp = -104,
    QMASDKProtoCodecErrorSeqNotMatch = -105,
    QMASDKProtoCodecErrorInvalidRspClsss = -106,
};

@interface QQMiniAppSDKManager : NSObject

+ (instancetype)sharedInstance;

@property (nonatomic, weak) id<QMASDKDelegate> sdkDelegate;
@property (nonatomic, weak) id<QMAAppEnvironmentDelegate> appEnvDelegate;
@property (nonatomic, weak) id<QQNetworkChannelDelegate> channelDelegate;
@property (nonatomic, weak) id<QQDownloadDelegate> downloadDelegate;
@property (nonatomic, weak) id<QMAContextDelegate> contextDelegate;
@property (nonatomic, weak) id<QMAStartUpProtocol> startUpDelegate;
@property (nonatomic, weak) id<QMAShareDelegate> shareDelegate;
@property (nonatomic, weak) id<QMAUIDelegate> uiDelegate;
@property (nonatomic, weak) id<QMACacheDelegate> cacheDelegate;
@property (nonatomic, weak) id<QMAConfigDelegate> configDelegate;
@property (nonatomic, weak) id<QMAAdvDelegate> advDelegate;
@property (nonatomic, weak) id<QMAVoIPDelegate> VoIPDelegate;
@property (nonatomic, weak) id<QMAFeatureToggleDelegate> featureToggleDelegate;

/// 呼起小游戏/小程序
/// @param link 伪链
/// @param scene 场景值
/// @param parentVC 从哪个vc呼起，不能为空
/// @param hostModel 可选，透传给宿主后台的心跳参数
- (void)showApplicationWithLink:(NSString *)link
                          scene:(MAEntryScene)scene
                       parentVC:(UIViewController *)parentVC
                      hostModel:(QMAHostModel *_Nullable)hostModel;

/// 通过AppID呼起小游戏/小程序
/// @param appID 小游戏小程序appID
/// @param scene 场景值
/// @param parentVC 从哪个vc呼起，不能为空
/// @param hostModel 可选，透传给宿主后台的心跳参数
- (void)showApplicationWithAppID:(NSString *)appID
                           scene:(MAEntryScene)scene
                        parentVC:(UIViewController *)parentVC
                       hostModel:(QMAHostModel *_Nullable)hostModel;

/// 获取审核保护策略
/// @param completionBlock 向后台请求的回调
/// canShow 是否可以展示小程序
/// error 如有代表请求失败
- (void)requestApplicationShowState:(void (^)(BOOL canShow, NSError *_Nullable error))completionBlock;


/// 自有分享渠道获取分享url
/// @param appInfo 小程序/小游戏信息
/// @param completionBlock 结果回调
- (void)requestShareURLWithAppInfo:(MAAppInfo *)appInfo
                   completionBlock:(void(^)(NSString * _Nullable dataToShare, NSError * _Nullable error))completionBlock;


/// 移除所有栈上与保活中的小程序和小游戏
- (void)clearAllApplications;


/// 移除小程序/小游戏所有相关缓存 包含资源包、基础库、小程序/小游戏沙箱数据
- (void)clearMiniAppCache;

/**
 * @brief 返回请求小程序/小游戏的下载URLString
 */
+ (NSString *_Nullable)miniAppRequestURLString;

@end

NS_ASSUME_NONNULL_END
